from MySQLPool import *

table_name="WECHAT_RECEIVE_OBJECT"
column_name_list="ID,BELONG_WECHAT_USER_ID,OBJECT_TYPE,OBJECT_NAME,CREATE_USER,CREATE_TIME,UPDATE_USER,UPDATE_TIME,LOGIC_DEL_FLAG"

def queryByWechatUserId(wechatUserId):
    if wechatUserId is not None:
        with dbpool.get_connection() as connection:
            receiveObjectList=connection.query("select * from {table_name} where LOGIC_DEL_FLAG=0 and BELONG_WECHAT_USER_ID = %(wechatUserId)s",{"wechatUserId":wechatUserId})
            connection.close()
            if receiveObjectList is None:
                return None
            else:
                return receiveObjectList
    return None


# def insert(wechatUser):
#     rows_affected=0
#     if wechatUser is not None:
#         with dbpool.get_connection() as connection:
#             insert_query = "insert into {table_name} ({column_name_list}) values (null,%(SYS_USER_ID)s,%(WECHAT_NUMBER)s,%(WECHAT_NAME)s,%(WECHAT_CREDENTIAL)s,%(CREATE_USER)s,%(CREATE_TIME)s,%(UPDATE_USER)s,%(UPDATE_TIME)s,0)"
#             rows_affected = connection.execute(insert_query, wechatUser)
#
#     return rows_affected